package com.ruoyi.system.billiards.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BilliardsGame;
import com.ruoyi.system.service.IBilliardsGameService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 比赛记录Controller
 *
 * @author ruoyi
 * @date 2024-12-11
 */
@RestController
@RequestMapping("/billiards/game")
public class BilliardsGameAdminController extends BaseController {
    @Autowired
    private IBilliardsGameService billiardsGameService;

    /**
     * 查询比赛记录列表
     */
    @PreAuthorize("@ss.hasPermi('billiards:game:list')")
    @GetMapping("/list")
    public TableDataInfo list(BilliardsGame billiardsGame) {
        startPage();
        List<BilliardsGame> list = billiardsGameService.selectBilliardsGameList(billiardsGame);
        return getDataTable(list);
    }

    /**
     * 导出比赛记录列表
     */
    @PreAuthorize("@ss.hasPermi('billiards:game:export')")
    @Log(title = "比赛记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BilliardsGame billiardsGame) {
        List<BilliardsGame> list = billiardsGameService.selectBilliardsGameList(billiardsGame);
        ExcelUtil<BilliardsGame> util = new ExcelUtil<BilliardsGame>(BilliardsGame.class);
        util.exportExcel(response, list, "比赛记录数据");
    }

    /**
     * 获取比赛记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('billiards:game:query')")
    @GetMapping(value = "/{gameId}")
    public AjaxResult getInfo(@PathVariable("gameId") Long gameId) {
        return success(billiardsGameService.selectBilliardsGameByGameId(gameId));
    }

    /**
     * 新增比赛记录
     */
    @PreAuthorize("@ss.hasPermi('billiards:game:add')")
    @Log(title = "比赛记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BilliardsGame billiardsGame) {
        billiardsGameService.insertBilliardsGame(billiardsGame);
        return toAjax(Boolean.TRUE);
    }

    /**
     * 修改比赛记录
     */
    @PreAuthorize("@ss.hasPermi('billiards:game:edit')")
    @Log(title = "比赛记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BilliardsGame billiardsGame) {
        return toAjax(billiardsGameService.updateBilliardsGame(billiardsGame));
    }

    /**
     * 删除比赛记录
     */
    @PreAuthorize("@ss.hasPermi('billiards:game:remove')")
    @Log(title = "比赛记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{gameIds}")
    public AjaxResult remove(@PathVariable Long[] gameIds) {
        return toAjax(billiardsGameService.deleteBilliardsGameByGameIds(gameIds));
    }
}
